<?php
class CompiledTemplate {
	
	private $className;
	private $source;
	private $evaluated;
	
	function __construct($className, $source) {
		$this->className = $className;
		$this->source = $source;	
	}
	
	/**
	 * Get an instance of this compiled template
	 *
	 * @param GeryEngine $engine
	 * @return TemplateBase
	 */
	function getInstance(GeryEngine $engine) {
		$this->evaluate();
		
		return new $this->className($engine);
	}
	
	/**
	 * Get the class name of the compiled template
	 *
	 * @return string
	 */
	function getClassName() {
		return $this->className;
	}
	
	/**
	 * Get the source code of this compiled template
	 *
	 * @return String
	 */
	function getSource() {
		return $this->source;
	}
	
	/**
	 * Evaluate the compiled template source code
	 *
	 * @return boolean True if the code is succesfully evaluated, False if the code was already evaluated
	 */
	private function evaluate() {
		if ($this->evaluated)
			return false;
			
		eval('?>' . $this->source);
		
		return true;
	}
}
?>